<?php
declare (strict_types = 1);

namespace app\common\model;

use think\Model;
use think\response\Json;

/**
 * @mixin \think\Model
 */
class Seckill extends Base
{

    protected $name = 'seckill';

    public static function saveSeckill($param)
    {
        parent::startTrans();
        try {
            $times= explode(' - ', $param['date_value']);
            $param['start_time']=strtotime($times[0]);
            $param['end_time']=strtotime($times[1]);
            //print('<pre>');print_r($param);die;
            if (isset($param['id']) && $param['id']) {
                $product = parent::update($param);
                $product->operation = 'save';
            } else {
                $product = parent::create($param);
                $product->operation = 'create';
            }

            //设置商品规格数据
            $product->save();

            parent::commit();
            return ['code' => 1, 'msg' => '操作成功！'];
        } catch (\Exception $e) {
            return ['code' => -1, 'msg' => $e->getMessage()];
        }
    }

    
    // public static function _update($param, $logs): array
    // {
    //     parent::startTrans();
    //     try {
    //         $id=$param['id'];
    //         if($param['val'] == 'true'){
    //            // print_r($param['id']);die;
    //             parent::where(['id','>',1])->update(array('status'=>0));
    //             $status=1;
    //         }else{
    //             $status=0;
    //         }
    //         parent::where(array('id'=>$id))->update(array('status'=>$status));

    //         parent::commit();
    //         return ['code' => 1, 'msg' => '操作成功'];
    //     } catch (\Exception $e) {
    //         return ['code' => -1, 'msg' => $e->getMessage()];
    //     }
    // }

}
